package com.smalluz.ad.modules.common.config;

import java.net.URI;
import java.net.URISyntaxException;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MediaHostConfig {

    public static final String API_DEFAULT_HOST = "https";
    //巨量引擎-字节
    public static final String API_DEFAULT_HOST_URL = "ad.oceanengine.com";

    //磁力引擎-快手
    public static final String KS_API_DEFAULT_HOST_URL = "ad.e.kuaishou.com";
    
    //百度营销开放平台
    public static final String BD_API_DEFAULT_HOST_URL = "api.baidu.com";
    private String apiHost;

    /**
     * Build request URL
     *
     * @param path Request path
     * @return Request URL
     */
    public static String buildUrl(String path) throws URISyntaxException {
        URI uri = null;
        if(path.contains("/rest/openapi/")) {
            uri = new URI(API_DEFAULT_HOST, KS_API_DEFAULT_HOST_URL, path,"");
        }else if(path.contains("/open_api/")) {
            uri = new URI(API_DEFAULT_HOST, API_DEFAULT_HOST_URL, path,"");
        }else if(path.contains("/json/sms/")) {
            uri = new URI(API_DEFAULT_HOST, API_DEFAULT_HOST_URL, path,"");
        }
        
        return uri.toString();
    }

    public static String buildKsUrl(String path) throws URISyntaxException {
        URI uri = new URI(API_DEFAULT_HOST, KS_API_DEFAULT_HOST_URL, path,"");
        return uri.toString();
    }

}
